﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using CalemShop.Forms;

namespace CalemShop
{
    public partial class FrmPrintBillPreview : Form
    {
        private PrintDocument doc = null;

        private CalemShop.Forms.FrmSale.BillPrinting _bill;

        public CalemShop.Forms.FrmSale.BillPrinting Bill
        {
            set { _bill = value; }
        }

        public PrintDocument PrintBillDoc
        {
            set { doc = value; }
        }

        public FrmPrintBillPreview()
        {
            InitializeComponent();
            this.DoubleBuffered = true;
            view.Paint += new PaintEventHandler(view_Paint);
        }

        void view_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.Clear(Color.White);
            CalemShop.Forms.FrmSale.PaintViewInvoice(g, _bill);
        }


        private void btPrint_Click(object sender, EventArgs e)
        {
            if (doc != null)
            {
                if (_bill != null)
                {
                    CalemShop.Forms.FrmSale.AddPrintingQueue(_bill);
                    doc.PrinterSettings.PrinterName = FrmCalemShop.GetBillPrinterNameFromRegistry();
                }
            }
        }

        private void FrmPrintBillPreview_Load(object sender, EventArgs e)
        {
            btClose.Focus();
        }

        private void btClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
